package com.zt.bus.line.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zt.bus.constant.BusConstant;
import com.zt.bus.line.service.DriverInterService;
import com.zt.servlet.ReqBean;
import com.zt.servlet.RequestAttribute;
import com.zt.servlet.Response;

import net.sf.json.JSONObject;

@Controller
@RequestMapping(value = "/driverInter")
public class DriverInterController {

	@Autowired
	private DriverInterService driverInterService;

	@RequestMapping(value = "/login")
	@ResponseBody
	public JSONObject driverLogin(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
		String driverNo = reqBean.getInfo("driverNo");
		String driverPhone = reqBean.getInfo("driverPhone");
		return Response.response(driverInterService.driverLogin(driverNo, driverPhone));
	}
	
	@RequestMapping(value = "/getDriverSchedule")
	@ResponseBody
	public JSONObject getDriverSchedule(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
		String driverNo = reqBean.getInfo("driverNo");
		return Response.response(driverInterService.getDriverSchedule(driverNo));
	}

	@RequestMapping(value = "/getCheckedPassengers")
	@ResponseBody
	public JSONObject getCheckedPassengers(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
		String planId = reqBean.getInfo("planId");
		Date rideDate = reqBean.getInfoDate("rideDate");
		return Response.response(driverInterService.getPassengers(planId, rideDate, true));
	}
	
	@RequestMapping(value = "/getUnCheckedPassengers")
	@ResponseBody
	public JSONObject getUnCheckedPassengers(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
		String planId = reqBean.getInfo("planId");
		Date rideDate = reqBean.getInfoDate("rideDate");
		return Response.response(driverInterService.getPassengers(planId, rideDate, false));
	}
	
	@RequestMapping(value = "/remindPassenger")
	@ResponseBody
	public JSONObject remindPassenger(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
		String passengerPhone = reqBean.getInfo("passengerPhone");
		String planId = reqBean.getInfo("planId");
		Date rideDate = reqBean.getInfoDate("rideDate");
		driverInterService.remindPassenger(passengerPhone, planId, rideDate);
		return Response.responseSuccess();
	}


	/**
	 * 司机扫码
	 *
	 * @param reqBean
	 * @return
	 */
	@RequestMapping(value = "/scanCode")
	@ResponseBody
	public JSONObject scanCode(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
		return driverInterService.scanCode(reqBean.getInfo("orderStr"), reqBean.getInfo("driverNo"));
	}

}
